package com.utils;

import java.util.Properties;
import org.apache.velocity.app.Velocity;

/**
 * VelocityEngine工厂
 * 
 * @author 码农小鹿
 */
public class VelocityInitializer {
	/**
	 * 初始化vm方法
	 * @throws OrmException 
	 */
	public static void initVelocity() throws OrmException {
		Properties p = new Properties();
		try {
			// 加载classpath目录下的vm文件
			//p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
			// 定义字符集
			//p.setProperty(Velocity.INPUT_ENCODING, "utf-8");
			p.setProperty("resource.loader", "class");
	        //设置velocity资源加载方式为file时的处理类
	        p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
			// 初始化Velocity引擎，指定配置Properties
			Velocity.init(p);
		} catch (Exception e) {
			throw new OrmException(e);
		}
	}
}
